﻿using System.Web;
using System.Web.Mvc;
using Fuse8.GlobalizationFramework.BusinessServices;

namespace Fuse8.GlobalizationFramework.MvcPowered.Extensions
{
    /// <summary>
    /// Provides extensions for MVC HtmlHelper
    /// </summary>
    public static class HtmlHelperExtensions
    {
        /// <summary>
        /// Resturns value from resource table
        /// </summary>
        /// <param name="html"></param>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string Literal(this HtmlHelper html, string key, string defaultValue = null)
        {
            return ResourceService.FindValue(key, defaultValue);
        }

        /// <summary>
        /// Returns value from resource table as HTML
        /// </summary>
        /// <param name="html"></param>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static IHtmlString RawLiteral(this HtmlHelper html, string key, string defaultValue = null)
        {
            return html.Raw(ResourceService.FindValue(key, defaultValue));
        }

        /// <summary>
        /// Resturns formatted value from resource table
        /// </summary>
        /// <param name="html"></param>
        /// <param name="key"></param>
        /// <param name="defaultValue"></param>
        /// <param name="paremeters">Parameters for formatting</param>
        /// <returns></returns>
        public static IHtmlString FormatLiteral(this HtmlHelper html, string key, string defaultValue = null, params object[] paremeters)
        {
            return  html.Raw(string.Format(ResourceService.FindValue(key, defaultValue), paremeters));
        }
    }
}